<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>渠道服务管理 - Layui</title>
<link rel="stylesheet" href="/layui/css/layui.css">
<link rel="stylesheet" href="/css/admin.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    @include('admin.header')
  </div>
  <div class="layui-side layui-bg-black">
    @include('admin.leftadmin')
  </div>

  <div class="layui-body">
    <input type="hidden" name="m" value="<?php $m = empty($m)?'':$m; echo $m?>">
    <form action="" method="post" style="margin-top: 20px">
    <div class="layui-form-item" style="float:left;">
      <div class="layui-inline">
        <label class="layui-form-label">关键字</label>
        <div class="layui-input-inline">
          <input type="tel" name="k" lay-verify="shopname" autocomplete="off" class="layui-input shopname" value='<?php echo $k?>'>
        </div>
      </div>
       <span style="width: 1120px;display: inline-block;"></span>
      <div class="layui-inline"><button class="layui-btn" lay-submit="" lay-filter="demo1">查询</button></div>
    </div>
   </form>
   <div class="layui-inline"><button class="layui-btn" lay-submit="" lay-filter="demo1"><a href="/admin/service/index" style="color:white">重置</a></button></div>
   <div style="margin-top: 50px">
    <table class="layui-table" lay-skin="line">
     <colgroup>
      <col width="100">
      <col width="100">
      <col width="300">
      <col width="300">
      <col width="300">
      <col width="150">
      <col width="250">
      <col>
     </colgroup>
     <thead>
      <tr>
        <th>ID</th>
        <th>店铺号</th>
        <th>店名</th>
        <th>服务名称</th>
        <th>服务内容</th>
        <th>服务价格</th>
        <th>操作</th>
      </tr> 
     </thead>
     <tbody>
     <?php foreach($res->results as $key=>$v):?>
      <tr>
        <td><?php echo $v['pid']?></td>
        <td><?php echo $v['mark']?></td>
        <td><?php echo $v['shopname']?></td>
        <td><?php echo $v['svname']?></td>
        <td><?php echo $v['content']?></td>
        <td>¥<?php echo $v['price']?></td>
        <td>
        <a href="/admin/service/addservice?pid=<?php echo $v['pid']?>" style="color:white"><button class="layui-btn layui-btn-small"><i class="layui-icon">&#xe654</i></button></a>&nbsp&nbsp
         <!-- <a href="change?pid=<?php echo $v['pid']?>" style="color:white"><button class="layui-btn layui-btn-small"><i class="layui-icon"></i></button></a>&nbsp&nbsp --><button class="layui-btn layui-btn-small change"><i class="layui-icon"></i></button>
         <button class="layui-btn layui-btn-small dele"><i class="layui-icon"></i></button>
        </td> 
      </tr>
    <?php endforeach;?>
     </tbody>
    </table> 
     <div id="page-v" style="margin-left: 50px"></div>  
   </div>
  </div>
  <div class="layui-footer">
    <!-- 底部固定区域 -->
  </div>

</body>
</html>

<script src="/layui/layui.js"></script>
<script src="/js/jquery-1.10.1.min.js"></script>
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form()
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
});

layui.use('layer', function(){
    var layer = layui.layer;
    $(function(){
      $('.dele').click(function(){
      var pid = $(this).parents('tr').find('td').eq(0).html();
      layer.confirm('确认删除?', function(index){
        $.ajax({
        url:'dele',
        type:'post',
        data:{'pid':pid},
        dataType:'json',
        success:function(d){
          if(d.code==200){
            layer.msg(d.msg, {
            icon: 1,
            time: 1000 //1秒关闭（如果不配置，默认是3秒）
          }, function(){
           window.location.reload();
          });  
          }else{
            layer.msg(d.msg);
          }
         }
        })
      layer.close(index);
   });    
  })
 })
});   

layui.use('element', function(){
  var element = layui.element(); //导航的hover效果、二级菜单等功能，需要依赖element模块  
});

layui.use(['laypage', 'layer'], function(){
  var total = <?php echo $res->last; ?>;
  var laypage = layui.laypage
  ,layer = layui.layer;
  //好像很实用的样子，后端的同学再也不用写分页逻辑了。
  laypage({
    cont: 'page-v',
    pages:<?php echo $res->last; ?>, //可以叫服务端把总页数放在某一个隐藏域，再获取。假设我们获取到的是18
    curr: function(){ //通过url获取当前页，也可以同上（pages）方式获取
      var page = location.search.match(/page=(\d+)/);
      return page ? page[1] : 1;
    }(), 
    jump: function(e, first){ //触发分页后的回调
      if(!first){ //一定要加此判断，否则初始时会无限刷新
        location.href = '?page='+e.curr+'&m=<?php echo $m?>'+'&k=<?php echo $k?>';
      }
    }
  });
});


layui.use(['laypage', 'layer'], function(){
  var layer = layui.layer;
  $('.change').on('click', function(){
  var pd = $(this).parents('tr').find('td').eq(0).html();
  layer.open({
  type: 2,
  title: '服务修改',
  maxmin: true,
  shadeClose: true, //点击遮罩关闭层
  area : ['800px' , '520px'],
  shade: [0.65],
  content: 'change?pid='+pd,
  end : function(){
    location.reload();
  }
  })
})
})

</script>


